<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>java - 肉蛋葱鸡肉粥🍛的博客☕</title><meta name="Description" content=""><meta property="og:title" content="java" />
<meta property="og:description" content="基础概念 JDK：java开发环境，java开发工具 javac：编译成.class字节码文件 java：运行.class文件 JRE：java运行" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://example.org/posts/java/" /><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2021-06-18T10:31:53+08:00" />
<meta property="article:modified_time" content="2021-06-18T10:31:53+08:00" /><meta property="og:site_name" content="肉蛋葱鸡肉粥🍛的博客☕" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="java"/>
<meta name="twitter:description" content="基础概念 JDK：java开发环境，java开发工具 javac：编译成.class字节码文件 java：运行.class文件 JRE：java运行"/>
<meta name="application-name" content="肉蛋葱鸡肉粥🍛的博客☕">
<meta name="apple-mobile-web-app-title" content="肉蛋葱鸡肉粥🍛的博客☕"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="http://example.org/posts/java/" /><link rel="next" href="http://example.org/posts/mysql/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "java",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "http:\/\/example.org\/posts\/java\/"
        },"genre": "posts","keywords": "java","wordcount":  7495 ,
        "url": "http:\/\/example.org\/posts\/java\/","datePublished": "2021-06-18T10:31:53+08:00","dateModified": "2021-06-18T10:31:53+08:00","publisher": {
            "@type": "Organization",
            "name": "yzuxqz"},"author": {
                "@type": "Person",
                "name": "yzuxqz"
            },"description": ""
    }
    </script></head>
    <body header-desktop="" header-mobile=""><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : '' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="肉蛋葱鸡肉粥🍛的博客☕">肉蛋葱鸡肉粥🍛的博客☕</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/about/"> 关于 </a><span class="menu-item delimiter"></span><a href="javascript:void(0);" class="menu-item language" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                        <select class="language-select" id="language-select-desktop" onchange="location = this.value;"><option value="/posts/java/" selected>简体中文</option></select>
                    </a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="肉蛋葱鸡肉粥🍛的博客☕">肉蛋葱鸡肉粥🍛的博客☕</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/about/" title="">关于</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a><a href="javascript:void(0);" class="menu-item" title="选择语言">简体中文<i class="fas fa-chevron-right fa-fw"></i>
                    <select class="language-select" onchange="location = this.value;"><option value="/posts/java/" selected>简体中文</option></select>
                </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">java</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://github.com/yzuxqz" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw"></i>yzuxqz</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/java/"><i class="far fa-folder fa-fw"></i>java</a>&nbsp;<a href="/categories/%E5%90%8E%E7%AB%AF/"><i class="far fa-folder fa-fw"></i>后端</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-06-18">2021-06-18</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 7495 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 15 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#关键字">关键字</a></li>
    <li><a href="#保留字">保留字</a></li>
    <li><a href="#标识符">标识符</a></li>
    <li><a href="#命名规范">命名规范</a></li>
    <li><a href="#注释">注释</a></li>
    <li><a href="#变量">变量</a></li>
    <li><a href="#数据类型">数据类型</a>
      <ul>
        <li><a href="#基本数据类型">基本数据类型</a></li>
        <li><a href="#引用数据类型">引用数据类型</a></li>
        <li><a href="#数据类型转换">数据类型转换</a>
          <ul>
            <li><a href="#自动类型转换">自动类型转换</a></li>
            <li><a href="#强制类型转换">强制类型转换</a></li>
            <li><a href="#string类型转数值类型">String类型转数值类型</a></li>
          </ul>
        </li>
      </ul>
    </li>
    <li><a href="#运算符">运算符</a>
      <ul>
        <li><a href="#算术运算符">算术运算符</a></li>
        <li><a href="#赋值运算符">赋值运算符</a></li>
        <li><a href="#比较运算符">比较运算符</a></li>
        <li><a href="#逻辑运算符">逻辑运算符</a></li>
        <li><a href="#位运算符">位运算符</a></li>
        <li><a href="#三元运算符">三元运算符</a></li>
      </ul>
    </li>
    <li><a href="#scanner类">Scanner类</a></li>
    <li><a href="#arrays类">Arrays类</a></li>
    <li><a href="#流程控制语句">流程控制语句</a>
      <ul>
        <li><a href="#流程分支语句">流程分支语句</a></li>
        <li><a href="#循环控制语句">循环控制语句</a>
          <ul>
            <li><a href="#for">for</a></li>
            <li><a href="#break">break</a></li>
            <li><a href="#continue">continue</a></li>
            <li><a href="#while">while</a>
              <ul>
                <li><a href="#do-while">do while</a></li>
              </ul>
            </li>
          </ul>
        </li>
      </ul>
    </li>
    <li><a href="#数组">数组</a>
      <ul>
        <li><a href="#一维数组">一维数组</a>
          <ul>
            <li><a href="#声名和初始化">声名和初始化</a></li>
            <li><a href="#添加和获取元素">添加和获取元素</a></li>
            <li><a href="#遍历数组">遍历数组</a></li>
            <li><a href="#数组元素的默认初始值">数组元素的默认初始值</a>
              <ul>
                <li><a href="#基本数据类型-1">基本数据类型</a></li>
                <li><a href="#引用数据类型-1">引用数据类型</a></li>
              </ul>
            </li>
            <li><a href="#数组的内存解析">数组的内存解析</a></li>
          </ul>
        </li>
        <li><a href="#二维数组">二维数组</a>
          <ul>
            <li><a href="#声名和初始化-1">声名和初始化</a></li>
            <li><a href="#添加和获取元素-1">添加和获取元素</a></li>
            <li><a href="#遍历二维数组">遍历二维数组</a></li>
            <li><a href="#二维数组的默认初始值">二维数组的默认初始值</a></li>
            <li><a href="#二维数组内存解析">二维数组内存解析</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>

  <ul>
    <li><a href="#属性">属性</a>
      <ul>
        <li><a href="#成员变量vs局部变量">成员变量vs局部变量</a></li>
      </ul>
    </li>
    <li><a href="#方法">方法</a>
      <ul>
        <li><a href="#声名">声名</a></li>
        <li><a href="#重载">重载</a></li>
        <li><a href="#值传递机制">值传递机制</a></li>
      </ul>
    </li>
    <li><a href="#匿名对象">匿名对象</a></li>
    <li><a href="#对象数组">对象数组</a></li>
    <li><a href="#构造器">构造器</a></li>
    <li><a href="#this关键字">this关键字</a></li>
    <li><a href="#封装">封装</a></li>
    <li><a href="#package">package</a>
      <ul>
        <li><a href="#jdk包介绍">jdk包介绍</a></li>
      </ul>
    </li>
    <li><a href="#import">import</a></li>
    <li><a href="#继承">继承</a></li>
    <li><a href="#重写">重写</a></li>
    <li><a href="#super">super</a>
      <ul>
        <li><a href="#super的使用">super的使用</a></li>
        <li><a href="#super调用构造器">super调用构造器</a></li>
      </ul>
    </li>
    <li><a href="#多态">多态</a>
      <ul>
        <li><a href="#向下转型">向下转型</a></li>
        <li><a href="#instance-of">instance of</a></li>
      </ul>
    </li>
    <li><a href="#和equals的区别">==和equals的区别</a></li>
    <li><a href="#重写tostring方法">重写toString方法</a></li>
    <li><a href="#包装类">包装类</a>
      <ul>
        <li><a href="#基本数据类型转包装类">基本数据类型转包装类</a></li>
        <li><a href="#包装类转基本数据类型">包装类转基本数据类型</a></li>
        <li><a href="#自动装箱与自动拆箱">自动装箱与自动拆箱</a></li>
        <li><a href="#基本数据类型包装类转string类型">基本数据类型包装类转String类型</a></li>
        <li><a href="#string类型转基本数据类型包装类">String类型转基本数据类型包装类</a></li>
      </ul>
    </li>
    <li><a href="#static关键字">static关键字</a>
      <ul>
        <li><a href="#类的生命周期">类的生命周期</a></li>
      </ul>
    </li>
    <li><a href="#代码块">代码块</a></li>
    <li><a href="#final关键字">final关键字</a></li>
    <li><a href="#抽象类">抽象类</a></li>
    <li><a href="#抽象方法">抽象方法</a></li>
    <li><a href="#接口">接口</a></li>
    <li><a href="#静态方法和默认方法">静态方法和默认方法</a></li>
    <li><a href="#内部类">内部类</a>
      <ul>
        <li><a href="#成员内部类">成员内部类</a>
          <ul>
            <li><a href="#static成员内部类">static成员内部类</a></li>
            <li><a href="#非static成员内部类">非static成员内部类</a></li>
          </ul>
        </li>
        <li><a href="#局部内部类">局部内部类</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h1 id="基础概念">基础概念</h1>
<p>JDK：java开发环境，java开发工具</p>
<ol>
<li>javac：编译成.class字节码文件</li>
<li>java：运行.class文件</li>
</ol>
<p>JRE：java运行环境，Java核心类库</p>
<p>JVM：java虚拟机，跨平台兼容</p>
<p>关系：JVM&raquo;JRE&raquo;JVM</p>
<h1 id="常用dos指令">常用DOS指令</h1>
<table>
<thead>
<tr>
<th>指令</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>d:</td>
<td>切换盘符</td>
</tr>
<tr>
<td>cd/cd..</td>
<td>切换文件夹/进入上一级</td>
</tr>
<tr>
<td>dir</td>
<td>文件列表</td>
</tr>
<tr>
<td>md</td>
<td>创建文件夹</td>
</tr>
<tr>
<td>rd</td>
<td>删除空文件夹</td>
</tr>
<tr>
<td>del</td>
<td>删除文件</td>
</tr>
<tr>
<td>echo 内容&gt;文件名.后缀</td>
<td>创建文件</td>
</tr>
<tr>
<td>chcp</td>
<td>jdk编码格式</td>
</tr>
</tbody>
</table>
<h1 id="基本语法">基本语法</h1>
<h2 id="关键字">关键字</h2>
<ul>
<li>电脑语言中事先定义，有特别意义的标识符</li>
<li>小写</li>
</ul>
<h2 id="保留字">保留字</h2>
<ul>
<li>特殊的关键字，无语义，未被java语言使用</li>
</ul>
<h2 id="标识符">标识符</h2>
<ul>
<li>
<p>由字母，数字，_，$组成</p>
</li>
<li>
<p>数字不能开头</p>
</li>
<li>
<p>不能使用关键字和保留字，但可以包含</p>
</li>
<li>
<p>区分大小写</p>
</li>
<li>
<p>不能包含空格</p>
</li>
</ul>
<h2 id="命名规范">命名规范</h2>
<ul>
<li>
<p>包名：小写</p>
</li>
<li>
<p>类名，接口名：大驼峰命名（首字母大写）</p>
</li>
<li>
<p>变量名&amp;&amp;方法名：小驼峰命名（首字母小写）</p>
</li>
<li>
<p>常量名：所有字母大写，_连接</p>
</li>
</ul>
<h2 id="注释">注释</h2>
<p>单行：//</p>
<p>多行：/* */</p>
<p>文本：/** */</p>
<h2 id="变量">变量</h2>
<p>变量概念：在内存中的一个存储区域，可以在同一类型范围内变换值，内存存储的最小单元</p>
<p>==注意==：先声明（数据类型 变量名 = 值），后使用，仅在自身作用域有效，不能重名</p>
<h2 id="数据类型">数据类型</h2>
<h3 id="基本数据类型">基本数据类型</h3>
<table>
<thead>
<tr>
<th>类型</th>
<th>占用存储空间</th>
<th>范围</th>
</tr>
</thead>
<tbody>
<tr>
<td>byte</td>
<td>1字节=8bit（bit是计算机中最小的存储单位）</td>
<td>-128-127</td>
</tr>
<tr>
<td>short</td>
<td>2字节</td>
<td>-2^15-2^15</td>
</tr>
<tr>
<td>int</td>
<td>4字节</td>
<td>-2^31-2^31-1</td>
</tr>
<tr>
<td>long</td>
<td>8字节（加L）</td>
<td>-2^63-2^63-1</td>
</tr>
<tr>
<td>float</td>
<td>4字节（加F）</td>
<td>小数点后7位</td>
</tr>
<tr>
<td>double</td>
<td>8字节（默认浮点类型）</td>
<td>小数点后14位</td>
</tr>
<tr>
<td>char</td>
<td>1字节（单引号）</td>
<td>单个字符</td>
</tr>
<tr>
<td>boolean</td>
<td></td>
<td>true/false</td>
</tr>
</tbody>
</table>
<h3 id="引用数据类型">引用数据类型</h3>
<table>
<thead>
<tr>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>String</td>
<td>多个字符</td>
</tr>
</tbody>
</table>
<h3 id="数据类型转换">数据类型转换</h3>
<h4 id="自动类型转换">自动类型转换</h4>
<p>不同数据类型运算时，取数范围小的类型会自动转为取数范围大的类型</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E8%87%AA%E5%8A%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png" /></p>
<p>==注意==：</p>
<ol>
<li>byte，short类型做运算，结果自动转为int类型</li>
<li>char类型在与数值类型做运算时取得AscII码值做运算，结果为int类型</li>
</ol>
<h4 id="强制类型转换">强制类型转换</h4>
<p>将取数范围大的数据类型转为取数范围小的数据类型</p>
<p>float a = (float) 2.9；</p>
<p>==注意==：会损失精度</p>
<h4 id="string类型转数值类型">String类型转数值类型</h4>
<p>int  i = Integer.parseInt(str)；</p>
<h2 id="运算符">运算符</h2>
<h3 id="算术运算符">算术运算符</h3>
<table>
<thead>
<tr>
<th>算术运算符</th>
<th></th>
<th>说明</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>+</td>
<td></td>
<td>加（字符串拼接）</td>
<td></td>
</tr>
<tr>
<td>-</td>
<td></td>
<td>减</td>
<td></td>
</tr>
<tr>
<td>*</td>
<td></td>
<td>乘</td>
<td></td>
</tr>
<tr>
<td>/</td>
<td></td>
<td>取整</td>
<td></td>
</tr>
<tr>
<td>%</td>
<td></td>
<td>取余</td>
<td></td>
</tr>
<tr>
<td>++</td>
<td></td>
<td>自增（后缀：先赋值，再自增，前缀：相反）</td>
<td></td>
</tr>
<tr>
<td>&ndash;</td>
<td></td>
<td>自减（后缀：先赋值，再自减，前缀：相反）</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="赋值运算符">赋值运算符</h3>
<table>
<thead>
<tr>
<th>赋值运算符</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>=</td>
<td>赋值</td>
</tr>
<tr>
<td>+=</td>
<td>i+=2相当于i=i+2</td>
</tr>
<tr>
<td>-=</td>
<td></td>
</tr>
<tr>
<td>*=</td>
<td></td>
</tr>
<tr>
<td>/=</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="比较运算符">比较运算符</h3>
<table>
<thead>
<tr>
<th>比较运算符</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>==</td>
<td>相等</td>
</tr>
<tr>
<td>!=</td>
<td>不等</td>
</tr>
<tr>
<td>&lt;/&lt;=</td>
<td></td>
</tr>
<tr>
<td>&gt;/&gt;=</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="逻辑运算符">逻辑运算符</h3>
<table>
<thead>
<tr>
<th>逻辑运算符</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;</td>
<td>左边为flase会继续执行右边</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>短路，左边为false不会执行右边</td>
</tr>
<tr>
<td>|</td>
<td>左边为true会继续执行右边</td>
</tr>
<tr>
<td>||</td>
<td>短路，左边为true不会执行右边</td>
</tr>
<tr>
<td>!</td>
<td>非</td>
</tr>
<tr>
<td>^</td>
<td>异或，相同为false，不同为true</td>
</tr>
</tbody>
</table>
<h3 id="位运算符">位运算符</h3>
<p>二进制</p>
<ol>
<li>正数</li>
</ol>
<ul>
<li>源码，反码，补码相同</li>
</ul>
<ol>
<li>负数</li>
</ol>
<ul>
<li>
<p>反码：符号位不变，源码取反</p>
</li>
<li>
<p>补码：符号位不变，源码取反加一</p>
</li>
</ul>
<table>
<thead>
<tr>
<th>位运算符</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>&laquo;</td>
<td>左移x位(&laquo;x),相当于原数*2^x</td>
</tr>
<tr>
<td>&raquo;</td>
<td>右移x位(&laquo;x),相当于原数/2^x ，==注意==：高位为0补0，高位为1补1</td>
</tr>
<tr>
<td>&raquo;&gt;</td>
<td>无符号右移，无论最高位是什么都补0</td>
</tr>
<tr>
<td>&amp;</td>
<td>二进制各个位相与</td>
</tr>
<tr>
<td>|</td>
<td>二进制各个位相或</td>
</tr>
<tr>
<td>^</td>
<td>二进制各个位相异或</td>
</tr>
<tr>
<td>~</td>
<td>非</td>
</tr>
</tbody>
</table>
<p>区别逻辑运算符：位运算符操作数值，逻辑运算符操作布尔值</p>
<h3 id="三元运算符">三元运算符</h3>
<p>条件表达式 ？语句1（表达式为true）：语句2（表达式为false）;</p>
<p>==注意==：必须根据返回值类型接收结果</p>
<h2 id="scanner类">Scanner类</h2>
<ol>
<li>
<p>导入jar包</p>
<p>java.util.Scanner;</p>
</li>
<li>
<p>创建Scanner实例</p>
<p>new Scanner(System.in);</p>
</li>
<li>
<p>使用Scanner类中的方法</p>
<p>next(),nextInt(),nextDouble(),next().charAt(0)</p>
</li>
</ol>
<h2 id="arrays类">Arrays类</h2>
<p>java.util.Arrays;</p>
<h2 id="流程控制语句">流程控制语句</h2>
<h3 id="流程分支语句">流程分支语句</h3>
<ul>
<li>if else</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="k">if</span><span class="o">(){</span>
<span class="o">}</span><span class="k">else</span> <span class="k">if</span><span class="o">(){</span>
<span class="o">}</span><span class="k">else</span><span class="o">{</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>switch case</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="k">switch</span><span class="o">(</span><span class="n">表达式</span><span class="o">){</span>
	<span class="k">case</span> <span class="n">常量1</span><span class="o">:</span><span class="n">语句1</span><span class="o">;</span>
        <span class="k">break</span><span class="o">;</span>
	<span class="k">case</span> <span class="n">常量2</span><span class="o">:</span><span class="n">语句2</span><span class="o">;</span>
        <span class="k">break</span><span class="o">;</span>
	<span class="k">case</span> <span class="n">常量3</span><span class="o">:</span><span class="n">语句3</span><span class="o">;</span>
        <span class="k">break</span><span class="o">;</span>
    <span class="k">default</span><span class="o">:</span><span class="n">语句4</span><span class="o">;</span>
        <span class="k">break</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>​		==注意==：表达式的类型只能是byte，short，int，char，String</p>
<p>​					 当没有break关键字时，匹配条件之后的代码都会去执行</p>
<h3 id="循环控制语句">循环控制语句</h3>
<h4 id="for">for</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="k">for</span><span class="o">(</span><span class="n">初始</span><span class="o">;</span><span class="n">条件</span><span class="o">(</span><span class="n">布尔表达式</span><span class="o">);</span><span class="n">代代</span><span class="o">){</span>
<span class="n">语句</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="break">break</h4>
<p>用于switch：结束当前switch</p>
<p>用于循环：结束循环，不继续下一次循环</p>
<h4 id="continue">continue</h4>
<p>跳出本次循环，继续下一次循环</p>
<h4 id="while">while</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="n">初始</span>
<span class="nf">while</span><span class="o">(</span><span class="n">条件</span><span class="o">){</span>
<span class="n">迭代</span>
<span class="n">语句</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>​	随机数：</p>
<ol>
<li>java.util.Random</li>
<li>new Random.nextInt(范围);</li>
</ol>
<h5 id="do-while">do while</h5>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback">初始
do{
迭代
语句
}while(条件)
</code></pre></td></tr></table>
</div>
</div><p>==区别==：先执行再判断，至少会执行一次</p>
<h2 id="数组">数组</h2>
<ol>
<li>数组是引用数据类型，数组元素不一定</li>
<li>数组的长度一旦确定，就不能更改</li>
<li>数组的创建会在内存开辟一连串连续的空间</li>
<li>数组引用的是连续内存空间的首地址</li>
</ol>
<h3 id="一维数组">一维数组</h3>
<h4 id="声名和初始化">声名和初始化</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//1.静态初始化：声名与初始化同时进行
</span><span class="c1"></span><span class="kt">int</span><span class="o">[]</span> <span class="n">arr</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[]{</span><span class="n">1</span><span class="o">,</span><span class="n">2</span><span class="o">,</span><span class="n">3</span><span class="o">}</span>
<span class="c1">//或者
</span><span class="c1"></span><span class="kt">int</span><span class="o">[]</span> <span class="n">arr</span> <span class="o">=</span> <span class="o">{</span><span class="n">1</span><span class="o">,</span><span class="n">2</span><span class="o">,</span><span class="n">3</span><span class="o">}</span><span class="c1">//类型推断
</span><span class="c1">//2.动态初始化
</span><span class="c1"></span><span class="n">String</span><span class="o">[]</span> <span class="n">arr</span> <span class="o">=</span> <span class="k">new</span> <span class="n">String</span><span class="o">[</span><span class="n">3</span><span class="o">];</span>
<span class="kt">double</span><span class="o">[]</span> <span class="n">arr6</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">double</span><span class="o">[</span><span class="n">3</span><span class="o">];</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="添加和获取元素">添加和获取元素</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//通过下标添加
</span><span class="c1"></span><span class="n">arr6</span><span class="o">[</span><span class="n">0</span><span class="o">]=</span><span class="n">12</span><span class="o">.</span><span class="na">3</span><span class="o">;</span>
<span class="n">arr6</span><span class="o">[</span><span class="n">3</span><span class="o">]=</span><span class="n">12</span><span class="o">;</span><span class="c1">//编译通过，运行出错，索引越界
</span></code></pre></td></tr></table>
</div>
</div><h4 id="遍历数组">遍历数组</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="k">for</span><span class="o">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">0</span><span class="o">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">arr</span><span class="o">.</span><span class="na">length</span><span class="o">;</span><span class="n">i</span><span class="o">++){</span>
    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">arr</span><span class="o">[</span><span class="n">i</span><span class="o">]);</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="数组元素的默认初始值">数组元素的默认初始值</h4>
<h5 id="基本数据类型-1">基本数据类型</h5>
<ul>
<li>
<p>整形：0</p>
</li>
<li>
<p>浮点型：0.0</p>
</li>
<li>
<p>char：0（ASCII码值）</p>
</li>
<li>
<p>boolean：false</p>
</li>
</ul>
<h5 id="引用数据类型-1">引用数据类型</h5>
<ul>
<li>null</li>
</ul>
<h4 id="数组的内存解析">数组的内存解析</h4>
<h3 id="二维数组">二维数组</h3>
<h4 id="声名和初始化-1">声名和初始化</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//1.静态初始化
</span><span class="c1">//String[][] arrs = new String[][]{{&#34;123&#34;,&#34;456&#34;}}
</span><span class="c1">//2.动态初始化
</span><span class="c1"></span><span class="kt">int</span><span class="o">[][]</span> <span class="n">arrs1</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[</span><span class="n">5</span><span class="o">][</span><span class="n">2</span><span class="o">]</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="添加和获取元素-1">添加和获取元素</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kt">int</span><span class="o">[][]</span> <span class="n">arr6</span> <span class="o">=</span> <span class="o">{{</span><span class="n">1</span><span class="o">,</span><span class="n">2</span><span class="o">}}</span><span class="c1">//类型推断
</span><span class="c1"></span><span class="n">arr6</span><span class="o">[</span><span class="n">1</span><span class="o">][</span><span class="n">1</span><span class="o">];</span>
<span class="n">arr6</span><span class="o">.</span><span class="na">length</span><span class="c1">//二位数组的长度
</span><span class="c1"></span><span class="n">arr6</span><span class="o">[</span><span class="n">0</span><span class="o">].</span><span class="na">length</span><span class="c1">//一维数组的长度
</span></code></pre></td></tr></table>
</div>
</div><h4 id="遍历二维数组">遍历二维数组</h4>
<p>嵌套循环</p>
<h4 id="二维数组的默认初始值">二维数组的默认初始值</h4>
<p>外层数组：null</p>
<p>内层数组：与一维数组元素默认初始值相同</p>
<h4 id="二维数组内存解析">二维数组内存解析</h4>
<h1 id="面向对象">面向对象</h1>
<h2 id="属性">属性</h2>
<h3 id="成员变量vs局部变量">成员变量vs局部变量</h3>
<p>相同点：</p>
<ol>
<li>声名赋值的方式一样</li>
<li>先声明再使用</li>
<li>都有自身的作用域</li>
</ol>
<p>不同点：</p>
<ol>
<li>
<p>成员变量可以使用权限修饰符：public protected 缺省 private</p>
<p>局部变量不能使用权限修饰符，修饰可以用static final关键字</p>
</li>
<li>
<p>成员变量可以不用显示初始化</p>
<p>局部变量必须进行显示初始化</p>
</li>
<li>
<p>内存的存放：</p>
<p>局部变量存放在栈中</p>
<p>成员变量存放在堆中</p>
</li>
<li>
<p>成员变量声名在类中</p>
<p>局部变量可以存放在方法中，方法的参数</p>
</li>
</ol>
<h2 id="方法">方法</h2>
<h3 id="声名">声名</h3>
<p>权限修饰符 返回类型 方法名（参数类型 参数1，&hellip;）{}</p>
<ol>
<li>
<p>权限修饰符</p>
<p>用来限定对象对该类成员（属性，方法）的一个访问权限</p>
<p>修饰属性</p>
<p>修饰方法</p>
<p>修饰类：只能使用public和缺省</p>
<table>
<thead>
<tr>
<th>权限修饰符</th>
<th>类内部</th>
<th>同一个包</th>
<th>不同包的子类</th>
<th>同一个工程</th>
</tr>
</thead>
<tbody>
<tr>
<td>public</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
</tr>
<tr>
<td>protected</td>
<td>yes</td>
<td>yes</td>
<td>yes</td>
<td></td>
</tr>
<tr>
<td>缺省（default）</td>
<td>yes</td>
<td>yes</td>
<td></td>
<td></td>
</tr>
<tr>
<td>private</td>
<td>yes</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</li>
<li>
<p>返回类型</p>
<ol>
<li>
<p>有返回值</p>
<p>返回值可以是变量，也可以是常量：return 返回数据；既返回值又结束方法</p>
</li>
<li>
<p>无返回值</p>
<p>void关键字，也可以用return;表示结束方法</p>
</li>
</ol>
</li>
<li>
<p>方法名</p>
<p>小驼峰</p>
</li>
<li>
<p>参数（形参）</p>
<p>局部变量</p>
</li>
<li>
<p>在同一个类中，方法1可以继续调用方法1（递归）</p>
</li>
<li>
<p>方法中不能再声名方法</p>
</li>
</ol>
<h3 id="重载">重载</h3>
<ol>
<li>在同一个类中</li>
<li>方法名相同</li>
<li>参数列表不同（参数个数，参数类型）</li>
</ol>
<h3 id="值传递机制">值传递机制</h3>
<p>基本数据类型：方法传递的是变量本身的值，方法的形参会开辟新的内存空间</p>
<p>引用数据类型：方法参数传递的是地址值</p>
<h2 id="匿名对象">匿名对象</h2>
<pre><code>new Person().name = &quot;Linc&quot;
</code></pre>
<p>==注意==：只能使用一次</p>
<h2 id="对象数组">对象数组</h2>
<p>Student[] s1 =  new Student[]</p>
<h2 id="构造器">构造器</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//无参构造器
</span><span class="c1"></span><span class="n">权限修饰符</span> <span class="nf">类名</span><span class="o">(){</span>
<span class="o">}</span>
<span class="c1">//有参构造器
</span><span class="c1"></span><span class="n">权限修饰符</span> <span class="nf">类名</span><span class="o">(</span><span class="n">形参</span><span class="o">){</span>
	<span class="k">this</span><span class="o">.</span><span class="na">xxx</span> <span class="o">=</span> <span class="n">参数</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>==注意==：构造器没有返回类型，构造器可以重载。每一个类都会提供一个默认的无参构造器，当我们在类中定义了一个有参的构造器，类中就不会再有无参构造器</p>
<h2 id="this关键字">this关键字</h2>
<p>可以放在方法中</p>
<p>构造器中</p>
<p>还可以在构造器中去调用其他的构造器</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//调用当前对象的无参构造器
</span><span class="c1"></span><span class="kd">public</span> <span class="nf">Constructor</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">){</span>
	<span class="k">this</span><span class="o">();</span>
	<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="c1">//调用当前对象的有参构造器
</span><span class="c1"></span><span class="kd">public</span> <span class="nf">Constructor</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">,</span><span class="kt">int</span> <span class="n">age</span><span class="o">){</span>
	<span class="k">this</span><span class="o">(</span><span class="s">&#34;xqz&#34;</span><span class="o">);</span>
	<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
  	<span class="k">this</span><span class="o">.</span><span class="na">age</span> <span class="o">=</span> <span class="n">age</span><span class="o">;</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="封装">封装</h2>
<p>表现</p>
<ul>
<li>属性私有化</li>
<li>通过公共的方法去操作私有的属性</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Person</span> <span class="o">{</span>
    <span class="kd">private</span> <span class="kt">int</span> <span class="n">age</span><span class="o">;</span>

    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setAge</span><span class="o">(</span><span class="kt">int</span> <span class="n">age</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="n">age</span> <span class="o">&gt;=</span> <span class="n">0</span> <span class="o">&amp;&amp;</span> <span class="n">age</span> <span class="o">&lt;=</span> <span class="n">130</span><span class="o">){</span>
            <span class="k">this</span><span class="o">.</span><span class="na">age</span> <span class="o">=</span> <span class="n">age</span><span class="o">;</span>
        <span class="o">}</span><span class="k">else</span><span class="o">{</span>
            <span class="k">this</span><span class="o">.</span><span class="na">age</span> <span class="o">=</span> <span class="n">20</span><span class="o">;</span>
        <span class="o">}</span>
    <span class="o">}</span>

    <span class="kd">public</span> <span class="kt">int</span> <span class="nf">getAge</span><span class="o">(){</span>
        <span class="k">return</span> <span class="n">age</span><span class="o">;</span>
    <span class="o">}</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="package">package</h2>
<ol>
<li>
<p>为了更好的实现项目中类的管理，提供包的概念</p>
</li>
<li>
<p>使用package声名类或接口所属的包，声名在源文件的首行</p>
</li>
<li>
<p>包，属于标识符，遵循标识符的命名规则，规范，见名知意</p>
</li>
<li>
<p>每”.“一次，就代表一层文件目录</p>
<p>==注意==：同一个包下，不能命名同名的接口和类</p>
</li>
</ol>
<h3 id="jdk包介绍">jdk包介绍</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/jdk%E5%8C%85%E4%BB%8B%E7%BB%8D.png" /></p>
<h2 id="import">import</h2>
<ol>
<li>在源文件中显示的使用import结构导入指定包下的类，接口</li>
<li>声名在包的声名和类的声名之间</li>
<li>如果需要导入多个结构，则并列写出即可</li>
<li>可以使用xxx.*的方式，表示可以导入xxx包下的所有结构</li>
<li>如果使用的类或接口是java.lang包下定义的，则可以省略import</li>
<li>如果使用的类或接口是本包下定义的，则也可以省略</li>
<li>如果同时引入不同的包里有同名的类，其中一个要com.xxx.xxx.类名来使用，import中只能有一个</li>
<li>使用”xxx.*“方式可以调用xxx包下的所有结构，但如果是xxx子包下的结构，仍需要显示导入</li>
<li>import static: 导入指定类或接口==里面==的静态结构</li>
</ol>
<h2 id="继承">继承</h2>
<p>extends&amp;&amp;super</p>
<h2 id="重写">重写</h2>
<p>子类覆盖父类的方法</p>
<p>前提：有继承关系</p>
<ol>
<li>
<p>子类的访问修饰符权限不能小于父类重写方法的访问修饰符权限</p>
<p>==注意==：父类中的private方法不能被重写</p>
</li>
<li>
<p>引用数据类型：子类重写的方法的返回值类型不能大于父类被重写的方法的返回值类型</p>
</li>
<li>
<p>基本数据类型：子类重写的方法的返回值类型（比如：double）必须和父类被重写的方法的返回值类型一模一样</p>
</li>
<li>
<p>对于方法名和参数列表：子类必须和父类相同</p>
</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="n">访问修饰符</span> <span class="n">返回类型</span>  <span class="nf">方法名</span><span class="o">(</span><span class="n">参数列表</span><span class="o">){</span>
     <span class="n">方法体</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>==区别==：方法的重写和重载</p>
<h2 id="super">super</h2>
<ol>
<li>
<p>理解为：父类的</p>
</li>
<li>
<p>可以用来调用：属性，方法，构造器</p>
<h3 id="super的使用">super的使用</h3>
<ol>
<li>可以在子类的方法或者构造器中中显式的调用父类的属性和方法，用super.属性或super.方法,但是通常会省略该super</li>
<li>特殊情况==：
<ol>
<li>当子类和父类定义了同名属性时，要想在子类中调用父类中的属性，不能省略super</li>
<li>当子类重写了父类的方法时，要想在子类中调用父类中方法，不能省略super</li>
</ol>
</li>
</ol>
<h3 id="super调用构造器">super调用构造器</h3>
<ol>
<li>
<p>在子类的构造器中显示的使用super（形参列表）的方式，调用父类中声名的指定的构造器</p>
</li>
<li>
<p>super(形参列表)的使用，必须声名在子类构造器的首行</p>
</li>
<li>
<p>注意：在类的构造器中，this(形参列表):调用本类中其他的构造器</p>
<p>和super(形参列表)只能二选一，如果什么都没写，默认会有super()，即父类的无参构造</p>
</li>
</ol>
</li>
</ol>
<h2 id="多态">多态</h2>
<p>前提：</p>
<ul>
<li>继承关系</li>
<li>方法重写</li>
</ul>
<ol>
<li>编译时看左边：编译时的类型看声名变量的类型，运行时看右边：new出来的类型</li>
<li>子类必须重写了父类的方法才能使用多态</li>
<li>子类中具有父类同名的属性和方法，在多态的情况下，使用的是父类的属性和子类的方法</li>
</ol>
<h3 id="向下转型">向下转型</h3>
<p>Cat cat = (Cat) animal</p>
<p>这样才能使用子类中独有的属性和方法</p>
<h3 id="instance-of">instance of</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="k">if</span><span class="o">(</span><span class="n">animal</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">Cat</span><span class="err">（</span><span class="n">这里是类型</span><span class="err">）</span><span class="o">{}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="和equals的区别">==和equals的区别</h2>
<ol>
<li>
<p>==：运算符 进行比较的</p>
</li>
<li>
<p>基本数据类型（除了boolean）间的比较,比较的是值</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="n">10</span><span class="o">;</span>
<span class="kt">int</span> <span class="n">b</span> <span class="o">=</span> <span class="n">20</span><span class="o">;</span>
<span class="n">a</span><span class="o">==</span><span class="n">b</span><span class="c1">//false
</span><span class="c1"></span>
<span class="kt">double</span> <span class="n">c</span> <span class="o">=</span> <span class="n">12</span><span class="o">.</span><span class="na">5</span><span class="o">;</span>
<span class="n">a</span><span class="o">==</span><span class="n">c</span><span class="c1">//false,int会自动转为double
</span><span class="c1"></span>
<span class="kt">char</span> <span class="n">d</span> <span class="o">=</span> <span class="n">10</span><span class="o">;</span><span class="c1">//10代表的是ascii码值为10的字符
</span><span class="c1"></span><span class="n">a</span><span class="o">==</span><span class="n">d</span><span class="c1">//true(char类型的运算是用ascii码值进行计算的)
</span><span class="c1"></span><span class="kt">char</span> <span class="n">e</span> <span class="o">=</span> <span class="sc">&#39;a&#39;</span><span class="o">;</span>
<span class="kt">char</span> <span class="n">f</span> <span class="o">=</span> <span class="n">97</span><span class="o">;</span>
<span class="n">e</span><span class="o">==</span><span class="n">f</span><span class="c1">//true
</span></code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>引用数据类型</p>
<p>比较的是地址</p>
<p>equals方法是java.lang.Object类提供的一个方法,内部还是用的==,String类对equals方法进行了重写，所以String类型的可以用equals进行比较</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="n">Person</span> <span class="n">person1</span><span class="o">/</span><span class="n">3</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Person</span><span class="o">(</span><span class="s">&#34;xqz&#34;</span><span class="o">,</span><span class="n">21</span><span class="o">)</span>
<span class="n">person1</span><span class="o">==</span><span class="n">person2</span><span class="c1">//false
</span><span class="c1"></span><span class="n">person1</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">person3</span><span class="o">)</span><span class="c1">//false，因为这里equals内部还是用的==，Person并没有进行重写
</span><span class="c1"></span>
<span class="n">String</span> <span class="n">str1</span> <span class="o">=</span> <span class="s">&#34;123&#34;</span><span class="o">;</span>
<span class="n">String</span> <span class="n">str2</span> <span class="o">=</span> <span class="s">&#34;123&#34;</span><span class="o">;</span>
<span class="n">str1</span> <span class="o">==</span> <span class="n">str2</span><span class="c1">//true，123属于方法区中的常量池，所以str1和str2都指向常量池中的123，String是个较为特殊的包装类型，直接用=“”创建的数据是存放在常量池
</span></code></pre></td></tr></table>
</div>
</div></li>
<li>
<p>一般来说，对于引用类型调用equals方法进行比较的时候，是调用Object类提供的equals方法，执行的==，比较的地址值</p>
</li>
<li>
<p>特殊情况：String，Date，File里重写了equals方法，比较的是值</p>
</li>
</ol>
<h2 id="重写tostring方法">重写toString方法</h2>
<p>toString</p>
<ul>
<li>
<p>java.lang.Object类提供</p>
</li>
<li>
<p>返回的是当前类的全类名+@+地址值（十六进制）</p>
</li>
<li>
<p>重写后输出实体值</p>
</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="n">Person</span> <span class="n">person</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Person</span><span class="o">(</span><span class="s">&#34;xqz&#34;</span><span class="o">,</span><span class="n">21</span><span class="o">)</span>
<span class="n">sout</span><span class="o">(</span><span class="n">person</span><span class="o">)</span><span class="c1">//输出地址，println()方法会先调用valueof()，然后在该方法里面再调用object的toString()
</span><span class="c1"></span>   
<span class="n">String</span> <span class="n">str</span> <span class="o">=</span> <span class="k">new</span> <span class="n">String</span><span class="o">(</span><span class="s">&#34;123&#34;</span><span class="o">);</span>
<span class="n">sout</span><span class="o">(</span><span class="n">str</span><span class="o">);</span><span class="c1">//输出123，str重写了toString方法
</span></code></pre></td></tr></table>
</div>
</div><p>==注意：==</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java">        <span class="kt">char</span><span class="o">[]</span> <span class="n">arr1</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="o">[]{</span><span class="sc">&#39;a&#39;</span><span class="o">,</span><span class="sc">&#39;b&#39;</span><span class="o">,</span><span class="sc">&#39;c&#39;</span><span class="o">};</span>
        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">arr1</span><span class="o">);</span><span class="c1">//abc
</span><span class="c1"></span>        <span class="kt">int</span><span class="o">[]</span> <span class="n">arr2</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[]{</span><span class="sc">&#39;a&#39;</span><span class="o">,</span><span class="sc">&#39;b&#39;</span><span class="o">,</span><span class="sc">&#39;c&#39;</span><span class="o">};</span>
        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">arr2</span><span class="o">);</span><span class="c1">//地址
</span><span class="c1"></span>        <span class="kt">double</span><span class="o">[]</span> <span class="n">arr3</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">double</span><span class="o">[]{</span><span class="n">12</span><span class="o">.</span><span class="na">4</span><span class="o">,</span><span class="n">3</span><span class="o">.</span><span class="na">6</span><span class="o">,</span><span class="n">5</span><span class="o">.</span><span class="na">6</span><span class="o">};</span>
        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">arr3</span><span class="o">);</span><span class="c1">//地址
</span></code></pre></td></tr></table>
</div>
</div><p>==解释==：println()方法中有char[]特有的重载方法，会打印char数组中的元素，其他类型的数组则没有重载方法，会进入valueof方法，然后调用object类中的toString方法，输出地址值。</p>
<h2 id="包装类">包装类</h2>
<p>基本数据类型，包装类，String类的数据类型转</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%8C%85%E8%A3%85%E7%B1%BB%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2.png" /></p>
<h3 id="基本数据类型转包装类">基本数据类型转包装类</h3>
<p>调用包装类的构造器</p>
<h3 id="包装类转基本数据类型">包装类转基本数据类型</h3>
<p>调用包装类的xxxValue()</p>
<p>==注意：==</p>
<ol>
<li>new Integer(&ldquo;xxx&rdquo;)，会自动转为int类型，但前提是xxx都是数字，否则会报错</li>
<li>Boolean中只要是和true不一样的都为false</li>
<li>包装类作为其他类的成员变量时默认值为null，因为它已经是一个类了</li>
</ol>
<h3 id="自动装箱与自动拆箱">自动装箱与自动拆箱</h3>
<ol>
<li>
<p>自动装箱</p>
<p>基本数据类型&ndash;&gt;包装类</p>
</li>
<li>
<p>自动拆箱</p>
<p>包装类&ndash;&gt;基本数据类型</p>
</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="n">10</span><span class="o">;</span>
<span class="n">Integar</span> <span class="n">in</span> <span class="o">=</span> <span class="n">a</span><span class="o">;</span><span class="c1">//自动装箱
</span><span class="c1"></span>
<span class="n">Integar</span> <span class="n">in</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Integar</span><span class="o">(</span><span class="n">12</span><span class="o">);</span>
<span class="kt">int</span> <span class="n">b</span> <span class="o">=</span> <span class="n">in</span><span class="o">;</span><span class="c1">//自动拆箱
</span></code></pre></td></tr></table>
</div>
</div><h3 id="基本数据类型包装类转string类型">基本数据类型包装类转String类型</h3>
<ol>
<li>连接运算</li>
<li>String类型的valueof方法</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="kt">int</span> <span class="n">num1</span> <span class="o">=</span> <span class="n">10</span><span class="o">;</span>
<span class="n">String</span> <span class="n">str1</span> <span class="o">=</span> <span class="n">num1</span> <span class="o">+</span><span class="s">&#34;&#34;</span>
    
<span class="n">String</span> <span class="n">str2</span> <span class="o">=</span> <span class="n">String</span><span class="o">.</span><span class="na">valueof</span><span class="o">(</span><span class="n">num1</span><span class="o">)</span>
    

</code></pre></td></tr></table>
</div>
</div><h3 id="string类型转基本数据类型包装类">String类型转基本数据类型包装类</h3>
<ol>
<li>
<p>调用包装类的parseXxx方法</p>
<p>转化之前必须保证这个数是可以转的</p>
</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="n">String</span> <span class="n">str1</span> <span class="o">=</span> <span class="s">&#34;123&#34;</span>
<span class="kt">int</span> <span class="n">num2</span> <span class="o">=</span> <span class="n">Integar</span><span class="o">.</span><span class="na">parseInt</span><span class="o">(</span><span class="n">str1</span><span class="o">)</span>
</code></pre></td></tr></table>
</div>
</div><p>注意：Integar的值在-128到127则是在常量池中直接取值，地址相同。&gt;127或者&lt;-128则会开辟新的地址。</p>
<h2 id="static关键字">static关键字</h2>
<p>修饰属性，方法，代码块，内部类</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/static.png" /></p>
<ol>
<li>
<p>非静态属性：属于类的对象，需要new创建对象才能调用，独立于每一个对象</p>
<p>静态属性：属于类，随着类的加载而加载，优先于对象创建，被类的所有对象所共享，当修改其中一个对象中的静态属性时，会改变其他对象的该属性，因为静态属性在静态域中，多个对象的该属性指向的是同一个静态域中的地址。调用方式：类名.属性</p>
</li>
<li>
<p>静态方法中，只能调用静态的方法和静态的属性，非静态方法中，都可以调用</p>
<p>静态方法中不能使用this，super关键字</p>
<p>通过类名.静态方法名，调用</p>
</li>
<li>
<p>开发中，属性是多个对象所共享的，不会随着对象的不同而改变，则声名为static。</p>
<p>类中的常量也声名为static</p>
</li>
</ol>
<h3 id="类的生命周期">类的生命周期</h3>
<p>类加载 .class 文件进行加载，未涉及到jvm</p>
<h2 id="代码块">代码块</h2>
<p>也是类的结构</p>
<ol>
<li>
<p>只能用static修饰，用来初始化类，对象</p>
</li>
<li>
<p>静态代码块：随着类的加载而执行，只执行一次，不能调用非静态的结构</p>
<p>​					  作用：初始化类的信息</p>
<p>非静态代码块：随着对象的创建而执行，每创建一个对象就执行一次非静态代码块。</p>
<p>​						 作用：可以在创建对象时，对对象的属性进行初始化</p>
</li>
<li>
<p>代码块可以存在多个按先后顺序执行</p>
</li>
<li>
<p>顺序：</p>
<p>由父及子，静态先行</p>
<ol>
<li>父类静态代码块</li>
<li>子类静态代码块</li>
<li>父类非静态代码块</li>
<li>父类无参构造器</li>
<li>子类的非静态代码块</li>
<li>属性</li>
<li>子类的无参构造器</li>
</ol>
</li>
<li>
<p>对属性赋值</p>
<ol>
<li>默认赋值</li>
<li>显示赋值/代码块</li>
<li>构造器</li>
<li>对象属性或方法</li>
</ol>
</li>
</ol>
<h2 id="final关键字">final关键字</h2>
<ol>
<li>
<p>修饰类：不能被继承</p>
</li>
<li>
<p>修饰方法：不能再被重写</p>
</li>
<li>
<p>修饰变量：</p>
<ul>
<li>
<p>修饰变量：常量</p>
</li>
<li>
<p>修饰属性：能显示初始化，在代码块中初始化，构造器中初始化</p>
</li>
<li>
<p>修饰局部变量：方法体中：常量</p>
<p>​						  形参：实参进行赋值后只能调用不能改变值</p>
</li>
</ul>
</li>
<li>
<p>static final 用来修饰属性：全局常量</p>
</li>
</ol>
<h2 id="抽象类">抽象类</h2>
<ol>
<li>不能实例化</li>
<li>抽象类中一定有构造器，便于子类实例化时调用</li>
<li>开发中，都会提供抽象类的子类，让子类对象实例化</li>
</ol>
<h2 id="抽象方法">抽象方法</h2>
<ol>
<li>
<p>抽象方法只有方法的声名，没有方法体</p>
</li>
<li>
<p>包含抽象方法的类，一定是一个抽象类。反之，抽象类中可以没有抽象方法</p>
</li>
<li>
<p>子类重写了父类所有的抽象方法，方可实例化。如果子类没有重写父类所有的抽象方法，则子类是一个抽象类</p>
<p>==注意：==</p>
<ol>
<li>abstract不能修饰属性，构造器</li>
<li>不能修饰私有方法，静态方法（静态方法不能被覆盖）</li>
</ol>
</li>
</ol>
<h2 id="接口">接口</h2>
<ol>
<li>在jdk7.0之前，接口中可以声名全局常量和抽象方法</li>
<li>接口没有提供构造器，不能进行实例化操作</li>
<li>在jdk8.0还可以在接口中声名静态方法和默认方法</li>
<li>使用i</li>
<li>mplements实现接口</li>
<li>如果不实现接口，类用abstract修饰</li>
<li>一个类实现了接口需要重写接口中所有的抽象方法</li>
<li>接口可以继承接口，且支持多继承</li>
</ol>
<h2 id="静态方法和默认方法">静态方法和默认方法</h2>
<ol>
<li>静态方法：public static void play(){}</li>
<li>默认方法：public default void sing(){}</li>
<li>调用静态方法：接口名.方法名</li>
<li>调用默认方法：需要创建子类对象，通过子类去调用</li>
</ol>
<h2 id="内部类">内部类</h2>
<h3 id="成员内部类">成员内部类</h3>
<ol>
<li>
<p>一方面作为外部类的成员</p>
<ul>
<li>可以调用外部类的结构</li>
<li>可以被static修饰</li>
<li>可以被4中不同的权限修饰</li>
</ul>
</li>
<li>
<p>另一方面，作为一个类</p>
<ul>
<li>
<p>类内可以定义属性，方法，构造器</p>
</li>
<li>
<p>可以用final修饰，表示此内部类无法继承。</p>
</li>
<li>
<p>可以被abstract修饰，表示不能被实例化</p>
</li>
</ul>
</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="c1">//实例化静态成员内部类
</span><span class="c1"></span><span class="n">Person</span><span class="o">.</span><span class="na">Dog</span> <span class="n">dog</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Person</span><span class="o">.</span><span class="na">Dog</span><span class="o">();</span>
<span class="n">dog</span><span class="o">.</span><span class="na">show</span><span class="o">();</span>
<span class="c1">//实例化非静态成员内部类
</span><span class="c1"></span><span class="n">Person</span> <span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Person</span><span class="o">();</span>
<span class="n">Person</span><span class="o">.</span><span class="na">Bird</span> <span class="n">bird</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="na">new</span> <span class="nf">Bird</span><span class="o">();</span>
<span class="n">bird</span><span class="o">.</span><span class="na">sing</span><span class="o">();</span>
<span class="c1">//内部类的方法调用同名参数
</span><span class="c1"></span><span class="n">name</span><span class="c1">//方法形参
</span><span class="c1"></span><span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="c1">//内部类的属性
</span><span class="c1"></span><span class="n">Person</span><span class="o">.</span><span class="na">this</span><span class="o">.</span><span class="na">name</span><span class="c1">//外部类的属性
</span></code></pre></td></tr></table>
</div>
</div><h4 id="static成员内部类">static成员内部类</h4>
<p>static class</p>
<h4 id="非static成员内部类">非static成员内部类</h4>
<h3 id="局部内部类">局部内部类</h3>
<p>方法内</p>
<p>代码块内</p>
<p>构造器内</p>
<h1 id="异常">异常</h1>
<ol>
<li>
<p>error</p>
<p>jvm无法解决的严重性问题</p>
<p>比如：stackoverflowError超出栈内存空间，oom超出堆内存空间</p>
</li>
<li>
<p>exception</p>
</li>
</ol>
<p>异常处理：</p>
<ol>
<li>try（可能出现异常的代码）-catch（出现异常后的逻辑）-finally（一定会执行的代码）</li>
<li>throws+异常类型，放在方法名之前。逐层向上抛出，子类继承父类时，父类抛出了异常，子类抛出的异常不大于父类抛出的异常</li>
<li>在方法中存在多个方法的调用，并且有多个方法存在递进关系的时候，一般在这几个方法中使用throws，最后在方法中使用try-catch</li>
</ol>
<p>自定义异常</p>
<ol>
<li>需继承于目前存在的异常，通常使用RuntimeException/Exception</li>
</ol>
<h1 id="string类">String类</h1>
<ol>
<li>final修饰的类，不能被继承</li>
<li>实现了Serializable接口，表示String类能够被序列化</li>
<li>实现了Cinparable接口，表示String类可以比较大小</li>
<li>实现了CharSequence接口：字符序列</li>
<li>String定义了一个final char[]数组存放字符内容</li>
<li>根据final的特性，推断出String是一个不可变的字符序列</li>
<li>通过字面量的方式给字符串赋值，会在字符串的常量池中开辟空间</li>
<li>字符串常量池不会存储相同的内容</li>
<li>改变字符串的内容时，不会改变原有的，而是重新开辟空间</li>
<li>两个字面量相加，在常量池中</li>
<li>有变量相加，都在堆中开辟空间，堆中有指向常量池中的地址，等同于new操作</li>
</ol>
<p>常用方法：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%951.png" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%952.png" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%953.png" /></p>
<h1 id="stringbuffer类">StringBuffer类</h1>
<p>可变的字符序列，线程安全的但是效率低</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png"
        data-srcset="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png 1.5x, https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png 2x"
        data-sizes="auto"
        alt="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png"
        title="https://raw.githubusercontent.com/yzuxqz/pic-bed/master/notes-img/StringBuffer%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95.png" /></p>
<h1 id="stringbuilder类">StringBuilder类</h1>
<p>可变的字符序列，线程不安全但是效率高</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-06-18</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/posts/java/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="http://example.org/posts/java/" data-title="java" data-via="xxxx" data-hashtags="java"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="http://example.org/posts/java/" data-hashtag="java"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="http://example.org/posts/java/" data-title="java" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="http://example.org/posts/java/" data-title="java"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="http://example.org/posts/java/" data-title="java"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="http://example.org/posts/java/" data-title="java" data-description=""><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="http://example.org/posts/java/" data-title="java" data-description=""><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="http://example.org/posts/java/" data-title="java"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/java/">java</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav">
            <a href="/posts/mysql/" class="next" rel="next" title="mysql">mysql<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.89.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://github.com/yzuxqz" target="_blank">yzuxqz</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
